﻿using System;
using WorkOrder.Business;
using System.Drawing;

namespace WorkOrder
{
    public partial class UserPWDModify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windohref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.parent.location.href='./login.aspx';</script>");
            }
            if (!IsPostBack)
            {
                txtUserName.Value = Session["UserLoginID"].ToString();
                txtUserName.Disabled = true;
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Business_Table_User b_t_user = new Business_Table_User();
            Model.Model_Table_User t_user = b_t_user.GetData(Session["UserID"].ToString());
            if (t_user.Password != txtUserPWDs.Value.Trim())
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windohef", "<script type='text/javascript'>alert('对不起，您输入的旧密码不正确！');</script>");
                return;
            }
            if (b_t_user.ModifyPassword(Session["UserID"].ToString(), Session["UserLoginID"].ToString(), Server.HtmlEncode(txtUserPWD2.Value.Trim())))
            {
                txtUserPWDs.Value = null;
                txtUserPWD.Value = null;
                txtUserPWD2.Value = null;
                lblMsg.ForeColor = Color.DarkGreen;
                lblMsg.Text = "提示信息：修改密码成功！";
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windohe", "<script type='text/javascript'>alert('密码修改成功，请牢记您的新密码并重新登录系统！');window.parent.parent.location.href='./login.aspx';</script>");
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "widohef", "<script type='text/javascript'>alert('对不起，修改密码失败！');</script>");
                lblMsg.ForeColor = Color.Red;
                lblMsg.Text = "提示信息：修改密码失败，请检查！";
            }
        }
    }
}
